package com.wj.ballcat.demo.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wj.ballcat.demo.converter.DemoConverter;
import com.wj.ballcat.demo.model.entity.Demo;
import com.wj.ballcat.demo.model.qo.DemoQO;
import com.wj.ballcat.demo.model.vo.DemoPageVO;
import com.hccake.ballcat.common.model.domain.PageParam;
import com.hccake.ballcat.common.model.domain.PageResult;
import com.hccake.extend.mybatis.plus.conditions.query.LambdaQueryWrapperX;
import com.hccake.extend.mybatis.plus.mapper.ExtendMapper;
import com.hccake.extend.mybatis.plus.toolkit.WrappersX;

/**
 * @author ballcat 2022-10-08 17:08:19
 */
public interface DemoMapper extends ExtendMapper<Demo> {

	/**
	 * 分页查询
	 * @param pageParam 分页参数
	 * @param qo 查询参数
	 * @return PageResult<DemoPageVO> VO分页数据
	 */
	default PageResult<DemoPageVO> queryPage(PageParam pageParam, DemoQO qo) {
		IPage<Demo> page = this.prodPage(pageParam);
		LambdaQueryWrapperX<Demo> wrapper = WrappersX.lambdaQueryX(Demo.class);
		this.selectPage(page, wrapper);
		IPage<DemoPageVO> voPage = page.convert(DemoConverter.INSTANCE::poToPageVo);
		return new PageResult<>(voPage.getRecords(), voPage.getTotal());
	}

}
